<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script>
        let base = '';
        const getRequest = (url,params) => {
            return axios({
                method : 'get',
                url : `${base}${url}`,
                params : params
            })
        }
        const postRequest = (url,params) => {
            return axios({
                method : 'post',
                url :  `${base}${url}`,
                params : params
            })
        }
        let params = {
            // key: '4ed65ae069cfb9645f57d4c53fb679ad',
            num: 5,
            page : 3
        }   

        // axios 响应拦截器
        axios.interceptors.response.use(success => {
            if(success.data){
                if(success.data.code == 200){
                    return success.data;
                }else{
                    if(success.data.msg){
                        alert(success.data.msg);
                    }
                    return;
                }
            }
        })

        getRequest('http://api.tianapi.com/esports/index',params).then(resp => { 
            if(resp){
                console.log(resp);
            }
        })
    </script> 
</body>
</html>